package cn.com.codingce.student.servlet;

import cn.com.codingce.student.entity.Student;
import cn.com.codingce.student.service.impl.StudentServiceImpl;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


/**
 * Servlet implementation class QueryAllStudentsServlet
 */
@WebServlet("/QueryAllStudentsServlet")
public class QueryAllStudentsServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
  
	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		
		
		StudentServiceImpl service = new StudentServiceImpl();
		List<Student> students = service.queryAllStudents();
		
		System.out.println(students);
		
		request.setAttribute("students", students);
		
		
		
		/*
		 * 因为request域中有数据
		 * 因此需要通过请求转发的方式跳转(重定向会丢失request域)
		 * pageContext<request<session<application
		 */
		
		
		request.getRequestDispatcher("index.jsp").forward(request, response);
		
	}


	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
